package com.stylefeng.guns.modular.pay.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.PayAllinBankCode;
import com.stylefeng.guns.modular.pay.model.PayChannel;
import com.stylefeng.guns.modular.pay.model.Trans;
import com.stylefeng.guns.modular.pay.model.WithdrawtAccount;
import com.stylefeng.guns.modular.pay.service.IPayAllinBankCodeService;
import com.stylefeng.guns.modular.pay.service.IWithdrawtAccountService;

/**
 * 提现帐号控制器
 *
 * @author fengshuonan
 * @Date 2018-09-11 17:00:42
 */
@Controller
@RequestMapping("/withdrawtAccount")
public class WithdrawtAccountController extends BaseController {

    private String PREFIX = "/pay/withdrawtAccount/";

    @Autowired
    private IWithdrawtAccountService withdrawtAccountService;
    @Autowired
    private IPayAllinBankCodeService payAllinBankCodeService;

    /**
     * 跳转到提现帐号首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "withdrawtAccount.html";
    }

    /**
     * 跳转到添加提现帐号
     */
    @RequestMapping("/withdrawtAccount_add")
    public String withdrawtAccountAdd(Model model) {
    	List<PayAllinBankCode> bankList = payAllinBankCodeService.selectList(new EntityWrapper<PayAllinBankCode>().orderBy("id", true));
    	model.addAttribute("bankList",bankList);
        return PREFIX + "withdrawtAccount_add.html";
    }

    /**
     * 跳转到修改提现帐号
     */
    @RequestMapping("/withdrawtAccount_update/{withdrawtAccountId}")
    public String withdrawtAccountUpdate(@PathVariable Integer withdrawtAccountId, Model model) {
        WithdrawtAccount withdrawtAccount = withdrawtAccountService.selectById(withdrawtAccountId);
        model.addAttribute("item",withdrawtAccount);
        LogObjectHolder.me().set(withdrawtAccount);
        return PREFIX + "withdrawtAccount_edit.html";
    }

    /**
     * 获取提现帐号列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(WithdrawtAccount account) {
    	Page<WithdrawtAccount> page = new PageFactory<WithdrawtAccount>().defaultPage();
    	List<WithdrawtAccount> result = withdrawtAccountService.selectList(account);
        page.setRecords(result);
        return super.packForBT(page);
    }

    /**
     * 新增提现帐号
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(WithdrawtAccount withdrawtAccount) {
    	withdrawtAccount.setCreateTime(new Date());
        withdrawtAccountService.insert(withdrawtAccount);
        return SUCCESS_TIP;
    }

    /**
     * 删除提现帐号
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer withdrawtAccountId) {
        withdrawtAccountService.deleteById(withdrawtAccountId);
        return SUCCESS_TIP;
    }

    /**
     * 修改提现帐号
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(WithdrawtAccount withdrawtAccount) {
        withdrawtAccountService.updateById(withdrawtAccount);
        return SUCCESS_TIP;
    }

    /**
     * 提现帐号详情
     */
    @RequestMapping(value = "/detail/{withdrawtAccountId}")
    @ResponseBody
    public Object detail(@PathVariable("withdrawtAccountId") Integer withdrawtAccountId) {
        return withdrawtAccountService.selectById(withdrawtAccountId);
    }
}
